'use strict';

//  不涉及主业务功能放此
const BaseController = require('../core/base_controller');
// var cache = require('memory-cache');
const shortid = require("shortid");
const md5Hex = require("md5-hex");
class UserOtherController extends BaseController {
   //登录 userLoginV
   async login() {
      // this.ctx.coreLogger.info(`APP登录 测试生产能还否打印 `+JSON.stringify()); //会打印到egg.web.log文件中
      const _ctx = this.ctx;
      // _ctx.throw("这是日志打印测试1这是什么",'logout1', "logout");
      const {
         service
      } = this.ctx;
      const validator = this.app.validator;
      try {
         const status = _ctx.validate(validator.userLoginV.userLogin);
         if (status.error) {
            this.validateFail("帐号或密码错误"); // "参数格式错误"
         } else {
            const params = _ctx.request.body;
            // console.log("参数", params);
            const isUser = await _ctx.model.User.findAll({ //先查一次,防止重复,不能放在create后
               where: {
                  userPhone: params.userPhone,
               },
               attributes: ['id', 'userPwd', "userCode", "isVip"]
            });
            // console.log("参数1", isUser);

            let md5Pasword = params.userPwd; //前端已经加密 md5Hex(params.userPwd);
            md5Pasword = _ctx.helper.restore(md5Pasword); //减掉盐
            // md5Pasword = md5Pasword.substring(0, 2) + md5Pasword.substring(3, md5Pasword.length)
            console.log(md5Pasword, isUser[0].userPwd)
            if (isUser.length > 0 && md5Pasword == isUser[0].userPwd) {
               const id = isUser[0].id
               const token = await service.tools.tokenSign(id); //生成token , params.userPhone
               // console.log(id, "登录token", isUser)
               await _ctx.model.Token.upsert({ //或用别名:insertOrUpdate
                  id: id,
                  token: token,
                  userId: _ctx.helper.parseInt(id) //id,
               })
               //后期可增加登录后把设备信息存储起来
               this.success({
                  status: isUser[0].isVip,
                  userCode: isUser[0].userCode,
                  id: id,
                  token: token,
               }, "登录成功!你已经进入了成功的大门!");
            } else {
               this.validateFail("帐号或密码错误2"); // "参数格式错误"
            }
         }
      } catch (e) {}
   }

   async changePassword() {
      const {
         ctx
      } = this;
      const {
         col
      } = this.app.Sequelize; //col 是配合  raw:true 
      try {
         const validator = this.app.validator;
         const status = ctx.validate(validator.userPswV.changePSW);
         // console.log(status, '======')
         if (status.error) {
            this.validateFail(status.error.details[0].message); // "参数格式错误"
         } else {
            const param = ctx.request.body;
            // const oldPSW = ctx.helper.restore(param.userPwd)
            const isUser = await ctx.model.Token.find({
               attributes: [col('user.id'), col('user.userPwd'), col('user.userPhone'), ],
               where: {
                  token: ctx.header.token,
                  // id: param.id,
               },
               include: [{
                  model: ctx.model.User,
                  as: 'user', //联合一定要加别名 
                  attributes: [], //加此空的比较好
               }],
               raw: true, //为 true时  上面的col才能正常使用
            });
            console.log(param)
            console.log(isUser);
            if (!isUser) {
               this.fail("修改失败,请确认输入信息正确性"); //没有此用户
            } else {
               if (isUser.userPwd != param.userPwd || isUser.userPhone != param.userPhone || param.id != isUser.id) {
                  this.fail("修改失败,请确认输入信息正确性!"); //没有此用户 
               } else {
                  const newPsw = ctx.helper.md5Hex(param.newPsw); //新密码没md5加密
                  if (newPsw == isUser.userPwd) { //新旧密码一样
                     this.success({}, '修改成功');
                  } else {
                     const s = await ctx.model.User.update({
                        userPwd: newPsw
                     }, {
                        where: {
                           id: isUser.id
                        }
                     })
                     if (s) {
                        this.success({}, '修改成功!');
                     }
                  }
               }
            }
         }

      } catch (e) {
         this.fail("未知错误,请联系客服")
      }
   }

   //WEB管理后台 作废
   async adminLogin() {
      const _ctx = this.ctx;
      const params = _ctx.request.body;
      console.log("管理登录1", params);
      const validator = this.app.validator;
      const status = _ctx.validate(validator.adminLogin.adminLogin);
      if (status.error) {
         _ctx.body = status.error.details[0].message;
      } else {
         console.log(999);
         const isHave = await _ctx.model.Admin.findOne({
            where: {
               loginName: params.userName,
               password: params.userPwd
            }
         });
         console.log("有查到authCode ", isHave)
         if (isHave && isHave.isLock < 3) {
            let token = _ctx.service.functionService.jwtSign(isHave.id, params.userName);
            const data = {
               success: true,
               status: 1,
               msg: "登录成功",
               data: {
                  authCode: isHave.authCode || 0,
                  token: token,
                  id: isHave.id
               }
            };
            await _ctx.model.Admin.update({ //3次登录成功清除为0
               isLock: 0,
               token: token,
            }, {
               where: {

                  loginName: params.userName,
               }
            })
            _ctx.helper.cache.put("adminToken", token, 300000);
            _ctx.body = data;
         } else {
            let isHaveLock = null
            try { //乱输入用户名的情况 
               isHaveLock = await _ctx.model.Admin.findOne({
                  where: {
                     loginName: params.userName,
                  }
               })

               await _ctx.model.Admin.update({
                  isLock: isHaveLock.isLock + 1
               }, {
                  where: {
                     loginName: params.userName,
                  }
               })
            } catch (e) {}

            let str = isHaveLock && isHaveLock.isLock > 2 ? '用户名/密码错误' : '登录失败'
            _ctx.body = {
               data: str,
               success: false
            };
            // return 
         }
      }
   }
   //APP管理后
   async adminLoginApp() {
      const _ctx = this.ctx;
      const service = this.service;

      const params = _ctx.request.body;
      console.log("管理登录1", params);
      const validator = this.app.validator;
      const status = _ctx.validate(validator.adminLogin.adminLogin);
      if (status.error) {
         _ctx.body = status.error.details[0].message;
      } else {
         let psw = _ctx.helper.restore(params.userPwd)
         // psw =   params.userPwd.substring(0, 2) + params.userPwd.substring(3, params.userPwd.length);
         console.log("减掉盐", psw); //减掉盐
         const isHave = await _ctx.model.Admin.findOne({
            where: {
               loginName: params.userName,
               password: psw
            }
         });
         // console.log("有查到authCode ", isHave)
         if (isHave && isHave.isLock < 3) {
            const token = await service.tools.tokenSign(isHave.id, 30);
            const data = {
               success: true,
               status: 1,
               msg: "登录成功",
               data: {
                  authCode: isHave.authCode || 0,
                  token: token,
                  id: isHave.id
               }
            };
            await _ctx.model.Admin.update({ //3次登录成功清除为0
               isLock: 0,
               token: token,
            }, {
               where: {
                  loginName: params.userName,
                  id: isHave.id
               }
            })
            // _ctx.helper.cache.put("adminToken", token, 300000);//不稳定 
            _ctx.body = data;
         } else {
            let isHaveLock = null
            try { //乱输入用户名的情况 
               isHaveLock = await _ctx.model.Admin.findOne({
                  where: {
                     loginName: params.userName,
                  }
               })

               await _ctx.model.Admin.update({
                  isLock: isHaveLock.isLock + 1
               }, {
                  where: {
                     loginName: params.userName,
                  }
               })
            } catch (e) {}

            let str = isHaveLock && isHaveLock.isLock > 2 ? '用户名/密码错误' : '登录失败'
            _ctx.body = {
               data: str,
               success: false
            };
            // return 
         }
      }
   }
   //后台 登出
   async adminLoginOut() {
      const {
         ctx
      } = this;
      ctx.helper.cache.del("adminToken");
      ctx.status = 200;
      ctx.body = {
         data: "成功",
         success: true
      };
      //del 
   }

   //以下PC
   ///禁用/启用
   async changeStatus() {
      const _ctx = this.ctx;
      const query = _ctx.query;
      const status = Number(query.status)
      // console.log(">>>>>>>>>>>>>>>>>>>>>>>>", status)
      if (query.id && status >= 0 && status < 2) {
         const pram = {
            userStatus: status,
         };
         const user = await _ctx.model.User.update(pram, {
            where: {
               id: Number(query.id)
            }
         });
         if (status == 1) {
            await _ctx.model.Token.destroy({
               where: {
                  userId: query.id
               }
            })
         }

         this.success({}, "更新成功")
         // _ctx.body = "更新成功";
      } else {
         this.validateFail("欠参数或参数错误")
         // _ctx.body = ;
      }
   }
   //开通会员功能  待完善
   async openVIP() {
      const _ctx = this.ctx;
      const params = _ctx.request.body;
      console.log("修改", params);
      if (!params.buyCount || !params.payChange) {
         this.validateFail("值有误")
         return
      }
      await pushMoney(params.userId, params.payChange);
      let para = {
         isVip: 1, //1为vip
         signIn: _ctx.helper.moment().format("YYYY-MM-DD 00:00:00")
      };
      await _ctx.model.Token.destroy({
         where: { //移除此开通的用户的token,使其重新登录
            userId: params.userId
         }
      })

      const user = await _ctx.model.User.update(para, {
         where: {
            id: params.userId
         }
      });

      await _ctx.model.User.increment({
         buyCount: params.buyCount,
         orderPay: params.payChange
      }, {
         where: {
            id: params.userId
         }
      })

      await _ctx.model.System.increment({
         selledCount: params.buyCount, //增加出售数量
      }, {
         where: {
            id: 1
         }
      })

      await _ctx.model.OrderBuy.destroy({ //移除申请记录
         where: {
            id: params.id
         }
      })

      await _ctx.model.Buyer.create({
         userId: params.userId,
         buyCount: params.buyCount,
         payMoney: params.payChange,
         userPayName: params.userPayName, //用户名  后台传
         payType: params.payType, //   
      })

      //  await _ct

      // console.log(">>>>>>>>>>>>>>>>>>>>>>>>", user);
      this.success({}, "开通成功");
      await _ctx.model.UserMessage.create({ //留言
         userId: params.userId,
         message: params.leaveMessage,
         messageType: 2,
      })



      async function pushMoney(id, payChange) { //3*提成实现 
         let one = payChange * 0.03;
         one = one.toFixed(2) * 1
         let two = payChange * 0.02;
         two = two.toFixed(2) * 1;
         let three = payChange * 0.01;
         three = three.toFixed(2) * 1;
         // console.log("三级>>",typeof one, two, three)
         const user0 = await _ctx.model.User.findById(id)
         // console.log(user0.dataValues.referralCode)
         const user1 = await _ctx.model.User.find({
            where: {
               userCode: user0.dataValues.referralCode
            },
            attributes: ["id", 'referralCode', 'userCode', 'deposit'],
         })
         if (!user1) { //
            // console.log(id, 'ta是最顶级了')
            return true
         }
         // console.log("-----证明有一级----", user1.dataValues)
         const oneID = user1.dataValues.id
         // let oneDeposit = user1.dataValues.deposit + one; //1级加分
         await _ctx.model.User.increment({
            deposit: one
         }, { //余额更新
            where: {
               id: oneID
            }
         })

         await _ctx.service.sequelizeService.addHistory({ //创建1级记录
            payType: null,
            money: one, //提了多少
            userId: oneID,
            historyType: 1,
         });

         const user2 = await _ctx.model.User.find({
            where: {
               userCode: user1.dataValues.referralCode
            },
            attributes: ["id", 'referralCode', 'userCode', 'deposit'],
         })
         // console.log("二级",user2)
         if (!user2) {
            // console.log("只有一级")
            return true
         }
         // console.log("-----证明有二级----", user2.dataValues)
         const twoID = user2.dataValues.id
         // let twoDeposit = user2.dataValues.deposit + two; //二级加分
         await _ctx.model.User.increment({
            deposit: two
         }, { //余额更新
            where: {
               id: twoID
            }
         })
         await _ctx.service.sequelizeService.addHistory({ //创建2级记录
            payType: null,
            money: two, //提了多少
            userId: twoID,
            historyType: 1,
         });

         const user3 = await _ctx.model.User.find({
            where: {
               userCode: user2.dataValues.referralCode
            },
            attributes: ["id", 'referralCode', 'userCode', 'deposit'],
         })
         // console.log("二级",user3)
         if (!user3) {
            console.log("只有二级")
            return true
         }
         console.log("-----证明有三级----", user3.dataValues)
         const threeID = user3.dataValues.id
         // let threeDeposit = user3.dataValues.deposit + three; //二级加分
         await _ctx.model.User.increment({
            deposit: three
         }, { //余额更新
            where: {
               id: threeID
            }
         })
         await _ctx.service.sequelizeService.addHistory({ //创建2级记录
            payType: null,
            money: three, //提了多少
            userId: threeID,
            historyType: 1,
         });
         console.log("三级ok")
         return true
      }


   } // <开通vip

   //PC查看个人信息
   async webGetPersonInfo() {
      const {
         ctx
      } = this;
      const p = ctx.request.body;
      let data = await ctx.model.User.findById(p.id, {
         attributes: {
            exclude: ['userPwd', 'isAdmin']
         }, //排除 密码
      })

      console.log(data, "个人资料", ctx.SHOP_MACHINE_AMOUNT)
      this.success({
         data: data,
         mostMachine: ctx.SHOP_MACHINE_AMOUNT
      }, "ok")
   }

   async getAllUser() {
      const _ctx = this.ctx;
      const query = this.ctx.query;
      console.log("get方式 ", query)
      // const user = await _ctx.model.User.findAll();
      const page = Number(query.page) || 10; //一页10个
      const pageNum = Number(query.pageNum) - 1 || 0;
      const user = await _ctx.model.User.findAndCount( //
         //分页
         {
            where: {
               // $not:[{isAdmin:1}], //不起作用了
            },
            limit: page,
            offset: pageNum * page,
            attributes: {
               exclude: ['userPwd']
            }, //排除 密码

         },
         // {
         //    include: [{
         //       model: _ctx.model.UserInfo
         //    }]
         // }
         //  { }
      );
      // console.log(user)
      user["mostMachine"] = _ctx.SHOP_MACHINE_AMOUNT
      this.success(user)
      // _ctx.body = ;
   }

   async clearVIP() { //问题待解决:要撤消上级推荐人的分成 
      const _ctx = this.ctx;
      const params = _ctx.request.body;
      console.log("修改", params);
      let para = {
         isVip: null, //清Vip      
      };
      const user = await _ctx.model.User.update(para, {
         where: {
            id: params.userId
         }
      });
      console.log(">>>>>>>>>>>>>>>>>>>>>>>>", user);
      this.success({}, "清除vip成功")
   }
   //web 获取tx申请列表
   async getApplicatioWithdrawal() {
      const {
         ctx
      } = this;
      const {
         col
      } = this.app.Sequelize; //col 是配合  raw:true
      const query = ctx.query;
      // console.log("11111", query)
      const page = Number(query.pageSize) || 10; //一页10个
      const pageNum = Number(query.pageNum) - 1 || 0;
      const result = await ctx.model.ApplicationWithdrawal.findAndCountAll({ //分页
         attributes: ['id', col('user.userPhone'), col('user.deposit'), col('user.firstPay'), 'applicationMoney', 'withdrawMoney', 'createdAt', 'remarks', 'userRemarks', 'status', 'userId'],
         include: [{
            model: this.ctx.model.User,
            as: 'user', //联合一定要加别名 
            attributes: [],
         }],
         //  where:{  },
         order: [
            ['createdAt', 'ASC'],
         ], //先申请的排在顶 
         limit: page,
         offset: pageNum * page,
         raw: true,
      })
      // console.log(result)
      this.success({
         ...result,
         mostMoney: ctx.MAXI_MUM_WITHDRAWAL
      }, 'ok')
   }

async deleApplicatioWithdrawal(){
   const {
      ctx
   } = this;
   const params = ctx.request.body;
   await ctx.model.ApplicationWithdrawal.destroy({ // 删除申提记录
      where: {
         id: params.id
      }
   })
   this.success({}, '删除成功')

}

   //用户fk和QR信息查看 ok
   async getUserQR() {
      const {
         ctx
      } = this;
      const {
         col
      } = this.app.Sequelize; // 
      const query = ctx.query;
      const userQR2 = await ctx.model.User.findById(query.id, {
         attributes: ['id', 'userPhone', 'wechart', 'alipay', "aliPayee", "wxPayee", 'bankName', 'bankPayee', 'bankCard', 'userStatus', 'isVip', 'firstPay'],
      })
        let userQR =JSON.parse(JSON.stringify(userQR2));//
      // console.log(userQR)
      if (userQR.firstPay == 1) {
         delete userQR.wechart;
         delete userQR.wxPayee;
         delete userQR.bankCard;
         delete userQR.bankName;
         delete userQR.bankPayee
      } else if (userQR.firstPay == 2) {
         delete userQR.alipay;
         delete userQR.aliPayee;
         delete userQR.bankCard;
         delete userQR.bankName;
         delete userQR.bankPayee
      } else if (userQR.firstPay == 3) {
         delete userQR.alipay;
         delete userQR.aliPayee;
         delete userQR.wechart;
         delete userQR.wxPayee;
      }
      this.success({
         data: userQR
      }, 'ok')
   }
   //web 成功tx申请确认
   async enterApplication() {
      const {
         ctx
      } = this;
      const params = ctx.request.body;
      const user = await ctx.model.User.findById(params.userId);

      if (user.dataValues.deposit < params.money) { //预防
         this.fail("数额大于已存数额");
         return
      }

      await ctx.model.User.decrement({ //减掉
         deposit: params.money //user.dataValues.deposit -
      }, {
         where: {
            id: params.userId
         }
      })

      await ctx.model.ApplicationWithdrawal.destroy({ // 删除申提记录
         where: {
            id: params.id
         }
      })


      this.success({}, 'ok')
      console.log("params", params)
      await ctx.model.WithdrawHistory.create({
         payType: params.payType,
         money: params.money, //提了多少
         userId: params.userId,
         historyType: 0, //0提现
      })

      await ctx.model.UserMessage.create({
         // id: params.id,
         userId: params.userId,
         message: params.remark,
         messageType: 0,
      })


   }
//删除申请
   async deleApplication(){
        
   }
   //web 私人消息发给ta
   async leaveMessage() {
      const {
         ctx
      } = this;
      const params = ctx.request.body;       
      await ctx.model.UserMessage.create({
         // id: params.id,
         userId: params.userId,
         message: params.remark,
         messageType: params.messageType || 0,
      })
      // }
      this.success({}, 'ok')
   }
   async getLeaveMessage() {
      const {
         ctx
      } = this;
      const params = ctx.request.body;
      console.log("=====", params)
      const msn = await ctx.model.UserMessage.findAll({
         where: {
            userId: params.id
         }
      }, {
         attributes: ['message']
      })
      console.log("--   --", msn)
      const msg = 'messageDelFlag' + params.id
      ctx.helper.cache.put(msg, 123)

      this.success({
         list: msn
      }, 'okppp')
   }

   async delLeaveMessage() { //用于app得到消息后的回调删除
      const {
         ctx
      } = this;
      const params = ctx.request.body;
      console.log("=====", params)
      const msg = 'messageDelFlag' + params.id
      const hereFlag = ctx.helper.cache.get(msg);
      if (hereFlag === params.random) {
         console.log(">>>>", params)
         ctx.helper.cache.del(msg)
         await ctx.model.UserMessage.destroy({ //先删除
            where: {
               userId: params.id
            }
         })

         this.success({}, 'ok')
      } else {
         // console.log(">>>>失败", )
         this.fail('no'); //删除失败,对不上口令
      }
   }



   //用户申go管理
   async getAllOrderBuy() {
      const {
         ctx
      } = this;
      const query = this.ctx.query;
      // console.log("get方式 ",query)
      // const user = await _ctx.model.User.findAll();
      const page = Number(query.page) || 10;
      const pageNum = Number(query.pageNum) - 1 || 0;
      const user = await ctx.model.OrderBuy.findAndCount(
         //分页
         {
            limit: page,
            offset: pageNum * page,
            // attributes: {
            //    exclude: ['userPwd', 'isAdmin']
            // }, //排除 密码

         }, {
            include: [{
               model: ctx.model.User
            }]
         }
         //  { }
      );
      this.success(user)


   }
   //web 删除下单记录 并留言, 2 会通知APP删除本地的下单记录
   async delOneOrder() {
      const {
         ctx
      } = this;
      const p = ctx.request.body;
      // console.log("-删除-", p.id)
      if (p.id) {
         await ctx.model.OrderBuy.destroy({
            where: {
               id: p.id //记录的id
            }
         })

         let msg = {
            messageType: 2,
            message: '审核购买失败或者原因是您没有支付,请联系客服!',
            userId: p.userId,
            orderCount: p.orderCount, //删除app的购物车数量
         }
         await ctx.model.UserMessage.create(msg)

         this.success({}, "删除ok")
      } else {
         this.fail("参数错误")
      }

   }

   async getWebVeriCode() {
      const {
         ctx
      } = this;
      // const logger = ctx.app.loggers; 
      //   console.log("头",ctx.header.token);  
      const captcha = await this.service.tools.webCaptcha();
      const uuid = ctx.header.token;
      // logger.log.info('这是验证码uuid='+uuid,captcha.text)
      // await this.service.tools.saveGetCache(uuid, captcha.text);
      console.log(captcha.text);
      await ctx.model.Captcha.upsert({ //或用别名:insertOrUpdate         
         deviceUUID: uuid,
         capctcha: captcha.text
      })
      this.ctx.body = {
         data: captcha.data
      };
   }
   //web推广注册
   async creat() {
      const {
         ctx
      } = this;
      let logger = ctx.app.loggers;
      // console.log("头",ctx.header.token);
      const uuid = ctx.header.token;
      // console.log(uuid.toLowerCase());
      if (uuid && uuid.length != 10) {
         this.fail("参数错误")
      } else {
         try {
            const validator = this.app.validator;
            const status = ctx.validate(validator.webV.webRegiste);
            //   console.log(status)
            if (status.error) {
               // logger.log.debug('这是验证错误',status.error)
               this.validateFail(status.error.details[0].message); // "参数格式错误"
               return
            }
            const p = ctx.request.body;
            // logger.log.debug('这是传参',p)

            const isCapctcha = await ctx.model.Captcha.findOne({
               where: {
                  $and: [{
                        capctcha: p.vcode
                     },
                     {
                        deviceUUID: uuid
                     }
                  ]
               }
            });
            if (!isCapctcha) {
               this.validateFail("验证码错误或失效,请点击刷新验证码"); // "参数格式错误"
               return false;
            }
            const time = ctx.helper.timeDiff(
               ctx.helper.moment(),
               isCapctcha.updatedAt
            );
            //  console.log("moment>>>>>>>>>>>>>", time / 60000)
            if (time / 60000 > 5) {
               //如果大于5分钟
               this.validateFail("验证码时效已过,请刷新验证码");
               return;
            }
            logger.log.info('这是读取的验证码' + uuid, isCapctcha.updatedAt)
            //   console.log( "--",isCapctcha.capctcha);//
            if (isCapctcha.capctcha.toLowerCase() != p.vcode.toLowerCase()) { //
               this.validateFail("验证码错误或失效,请点击刷新验证码"); // "参数格式错误"
               return false;
            }
            const isCode = await ctx.model.User.findOne({
               where: {
                  userCode: p.code
               },
               attributes: {
                  exclude: ['userPwd', 'alipay', 'wechart']
               }, //排除 密码
            })
            // console.log("有没有注册过的码", isCode)
            if (!isCode) {
               this.validateFail("无效的推荐码"); // "参数格式错误"
               return
            }
            const isUser = await ctx.model.User.findOne({
               where: {
                  userPhone: p.phone
               }
            })
            // //  console.log(isUser)
            if (isUser) {
               this.validateFail("手机号已被注册"); // "参数格式错误"
               return
            }

            let userCode = shortid.generate(); //生成推荐码 
            const isUserCode = await ctx.model.User.findOne({
               //先查一次,防止重复,不能放在create后
               where: {
                  userCode: userCode
               }
            });
            //   console.log(userCode,"==",isUserCode);
            let md5Pasword = md5Hex(p.psw); //  md5加密密码再保存            
            const isSU = await ctx.model.User.create({
               userPwd: md5Pasword,
               userPhone: p.phone,
               referralCode: p.code,
               userCode: userCode, //自己的推荐码 
               whoseProxy: isCode.whoseProxy, //代理伞下标志  ok  
               uuid:uuid,//注册的设备       
            });
            //  console.log('isSU,isSU',isSU);
            await ctx.model.User.update({
               //要更新推荐人的人数
               recommendedAmount: isCode.recommendedAmount + 1
            }, {
               where: {
                  id: isCode.id
               }
            });
            //   const tuijian=  await ctx.model.User.increment({// 
            //       recommendedAmount: 1
            //    }, { //推荐人加1 
            //       where: {
            //          id: isCode.id
            //       }
            //    })

            logger.log.info('注册推荐人增加1', "末加1前=" + isCode.recommendedAmount + ',推荐人号码=' + isCode.userPhone + ",当前注册号=" + p.phone+",uuid="+uuid)
            const sys = await ctx.model.System.findById(1);
            // console.log("系统参数",sys);
            this.success({
               url: sys.appUrl
            }, "注册成功");
            await ctx.model.Captcha.destroy({
               where: {
                  deviceUUID: uuid
               }
            })
         } catch (e) {
            console.log(e)
            this.validateFail("参数格式错误"); // "参数格式错误"
         }
      }
   }
   async findPassword() {
      const {
         ctx
      } = this;
      const p = ctx.request.body;
      if (p.id && p.email && p.phone) {
         this.fail("缺少参数");
         return
      }
      await ctx.model.FindPSW.create({
         phone: p.phone,
         email: p.email,
      })
      this.success({}, "提交成功,请注意查收");
   }
}

module.exports = UserOtherController;